package it.asvp.asvp_portal.web.controller;

 
import it.asvp.asvp_portal.asvp_util.util.Constants;

import java.security.Principal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
//import org.springframework.beans.factory.annotation.Value;
 
@Controller
@RequestMapping("/authentication")
public class AuthenticationController extends BaseController{
 
	@Autowired
	HomeController homeController;
	
	@RequestMapping(value="/login", method = RequestMethod.GET)
	public ModelAndView login(ModelMap model) {
		try{
		
		ModelAndView mv=new ModelAndView(Constants.REDIRECT+"/home");
		return mv;
		
		}catch (Exception e) {
		   return getErrorModelAndView(e);
		}
		
	}
	
	@RequestMapping(value="/success", method = RequestMethod.GET)
	public ModelAndView success(ModelMap model, Principal principal ) {
 
		try{
			
		String name = principal.getName();
		ModelAndView mv=new ModelAndView(Constants.REDIRECT+"/home/addLoginMessage?message="+"Benvenuto "+name);
		return mv;
		
		}catch (Exception e) {
			   return getErrorModelAndView(e);
			}
 
	}
 
	@RequestMapping(value="/failure", method = RequestMethod.GET)
	public ModelAndView failure(ModelMap model) {
		
		try{
			
		ModelAndView mv=new ModelAndView(Constants.REDIRECT+"/home/addLoginMessage?message="+"Login Fallito");
		return mv;
		
	    }catch (Exception e) {
		   return getErrorModelAndView(e);
		}
 
	}
	
	@RequestMapping(value="/logout", method = RequestMethod.GET)
	public ModelAndView logout() {
 
		try{
			
		ModelAndView mv=new ModelAndView(Constants.REDIRECT+"/home/addLoginMessage?message="+"Logout eseguito");
		return mv;
 
		}catch (Exception e) {
			   return getErrorModelAndView(e);
		}
	}
	
	@RequestMapping(value="/denied", method = RequestMethod.GET)
	public String denied(ModelMap model) {
 
		return "authentication/denied";
 
	}
	
}